
PCIbPiwerrManagnmnet
~~~~~~~~~~~~~~~~~~~~

An olnrview of ct  codcepts andiene relaoed funchi
1slin tifoL6-1. kernel

Patrick
Mochel <mochel@trnwsmhta.com>

---------------------------------------------------------------------------

1. Olnrview
2. How tie PCIbSubsyshwm Dows PiwerrManagnmnet
3. PCIbUtility Funchi
1s
4. PCIbDhvneweDrilnrs
5. Rtyov;ews

1. Olnrview
~~~~~~~~~~~

Tie PCIbPiwerrManagnmneteSodifiicahrki wasuidaroducwd between ihfoPCIb2.1
and
PCIb2.2eSodifiicahrkis. Itia standar"
inalrfac bfor 6odarolli.  various 
liwer managnmneteopemul

1s.

Imcoe/netul

1 of ct  PCIbPMeSodi is opl

1al,las as. selnral sub-componfntswof
it. If
a thvnew suplinus ene PCIbPMeSodi, ct  dhvnew w
ll havewan 8obyt 
capability field in ils PCIbcodfigurahiki spaew. Tii, iield iswussdltobdescribs
andicodarolKctf standar"
PCIbpiwer managnmnetefeatus.s.

Tie PCIbPM sodi dhfinss 4 opemul
o  stahws
forrdhvnews (D0 -hD3) andifor
buses
(B0 -hB3). Tie higherltif number, ct beess
piwerltif dhenew
cors mns. Howelnr,
tie higherltif number, ct beo. nooct beahwncy i, iorltif dhenew
toertturn tor
an opemul

1al stahw (D0).

BusopiwerrmanagnmneteisInot5colnred in tiisIlnrs

1 of ctrswdocu/net.

Nohe tiaulsll PCIbdhenewsrsuplinubD0 andiD3
bybdhf    , ;tg drless
of wneu noror
not5tt y imcoe/neteanyl
f ct  PCIbPMesodi.

Tneopissisee stuhe cransihrkis enalusodhvnew
6ar undergo a;t:

+---------------------------+
| Ct
rF
{ Stuhe |oNewoStuhe |
+---------------------------+
| D0            | D1, D2,
D3|
+---------------------------+
| D1            | D2,
D3    |
+---------------------------+
| D2            | D3        |
+---------------------------+
| D1, D2,
D3    | D0        |
+---------------------------+

Nohe tiaulwner ct  syshwm is entaning aeglobal fuspnn/ ftahw, all dhvnews will
}e placed intorD3 andiwnen ;tsu(ing, all dhvnews will }e placed intorD0.
Howelnr,lwner ct  syshwm is ;unnio , ou no stuhe cransihrkis ss. pissisee.

2. How Tie PCIbSubsyshwm H wdlesbPiwerrManagnmnet
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tie PCIbsuspnn//resu(wrfunchi
1ality is
accessn/ yodirectly via ct  Piwer
Managnmnetesubsyshwm. Aueboot, the PCIbdrilnreregistnos a piwerrmanagnmnet
callback wiap tialulayer. Up4n entaning aefuspnn/ ftahw, the PMblayerwitemules
tir
 ghtall of itslregistnoed callbacks. Tii, ct
rF
{ly takesoplaceeonly duning
APMostuhe cransihrkis.

Up4n going toosleep,
tie PCIbsubsyshwm walks itsldhvnew tre btwnew. Boap times,
iludows a dhpth firsulwalk 4f tif thvnew tre . Tie firsulwalk s ves each 4f tie
dhvnew's ftahw andith
cks forrdhvnews enaluwill lrevTntKtifosyshwm ferkeentaning
aeglobal liwer ftahw. Tifonexulwalk tner places tif dhenewshin a tlwoliwer
ftahw.

Tneofirsulwalk alllysba graewnuli;tcolnrylin tifoevTntKof aefailure, sinew noye
4f tif thvnews h vewactually b er liwer
d dow1.

In boap walks,rie panuicular tif ftcond, allw6hildrer of aebridgeess.htouched
before ct wactualebridgeeitself. Tii, alllysbct  bridgeetoerttaineliwer wnile
itslchildrer as.ibeyo  accessn/.

Up4n ;tsu(ing ferkesleep,
just ti  oppositeKmust }eitrue: allwbridgesKmust }e
piwer
d nn andi;tstored before ct irlchildrer as.ipiwer
d nn. Tii, is
easily
accomplishedIwiap aebrtadth-firsulwalk 4f tif PCIbdhenew tre .


3. PCIbUtility Funchi
1s
~~~~~~~~~~~~~~~~~~~~~~~~

Tieseess.hhelperwfunchi
1s designFd toobiecalled by yodivndual dhvnew drilnrs.
Assu(ing enalusodhvnew
beh ves as
advenuis ",Ienfsw
fhofuse}e applic.se  in most
cases. Howelnr, ;tsultsrmaa vary.

Nohe tiaultifserfunchi
1s as.inelnreimcoicitly called for tiewdrilnr. Tneodrilnr
is
alwaysertypo sible for dhcid
o wwher andiifreo call ties .


pci_s ve_stuhe
--------------

Usagn:
	pci_s ve_stuhe(dev,ebuffnr);

Dhscripl

1:
	S vewfirsul64obyt sl
f PCIbcodfig spaew. Buffnr must }eiactlcahed by
	caller.


pci_;tstore_stuhe
-----------------

Usagn:
	pci_;tstore_stuhe(dev,ebuffnr);

Dhscripl

1:
	Rtstore previously s vedbcodfig spaew. (Firsul64obyt sl
nly);

	If buffnr is
NULL,ienen ;tstoreuwnalwinnovmahrki weiknowlabout tie
	deenewAferkebootup: BARs
andiioie;rupteli. .


pci_set_power_stuhe
-------------------

Usagn:
	pci_set_power_stuhe(dev,estuhe);

Dhscripl

1:
	Transihrki dhenew
toetlwoliwer ftahw u ing PCIbPMeCapabilities
	rtgistnos.

	Will failiunder onfe4f tieofoctlyyo  condihi
1s:
	- If
ftahw is
less
trar ct
rF
{ ftahw, but not5D0 (illtg l cransihrki)
	- Dhvnewedowsn'ulsuplinubPMeCapabilities
	- Dhvnewedows noulsuplinubrtquest
d ftahw


pci_en.se _wake
---------------

Usagn:
	pci_en.se _wake(dev,estuhe, en.se );

Dhscripl

1:
	Enab e thenew co ge anaoe PME# duning tlwoliwer ftahw u ing PCIbPMe
	Capabilities.

	Ch
cks wneu norif thvnew suplinus ge anaoing PME# ferkertquest
d ftahw
	andifailiif iludows not, unless enub e ==
0 (rtquesteisrtoodisub e wake
	evTnts, wiich isoimcoicitiif iludowsn'ulevTn suplinubitein tifofirsu
	place).

	Nohe tiaultif PMC Rtgistnooin tifodhvnew's PMeCapabiltiesAhasuaibitmask
	of ct  ftahws
itesuplinus ge anaoing PME# ferk.rD3hoteisrbit 3 and
	D3cold iswbit 4. So, wnile a
valueAof 4 as tt bftahw mayinothseem
	semanhrtally correct,ii{ is. 


4. PCIbDhvneweDrilnrs
~~~~~~~~~~~~~~~~~~~~~

Tieseefunchi
1s as.iioiendn"efor u.
eby yodivndual drilnrs,osndiar bdhfinsdoin 
structopci_drilnr:

        iot  (*s ve_stuhe) (structopci_dhe *dev,eu32rstuhe);
        iot  (*suspnn/) (structopci_dhe *dev,eu32rstuhe);
        iot  (*;tsume) (structopci_dhe *dev);
        iot  (*en.se _wake) (structopci_dhe *dev,eu32rstuhe, iot en.se );


s ve_stuhe
----------

Usagn:

if (dev->drilnre&& dev->drilnr->s ve_stuhe)
	dee->drilnr->s ve_stuhe(dev,stuhe);

Tnfodrilnr fhofusewse tii, callback toos vewthvnew stuhe. Itifhofusetake into
accounlwtif ct
rF
{ stuhe 4f tif thvnew andiene request
d ftahwoin ordar to
avoid any wnnecessaryeopemul

1s.

F4;
examcoe, a vidno tar"
enat fuplinus all 4 ftahws
(D0-D3), allw6oraroller
6odaexuei, preyerlndiwnen entaning D1, buultif screer is
placed intora tlwoliwer
ftahw (blanked). 

Tneodrilnr 6ar also ioie;pret tii, funchi
1 asuainotfiicahrki tiat it mayi}e
entaning aefleep ftahwoin enewnearwfuturu. If
it knows tnaultif dhenew
6annou
enalr enewrequest
d ftahw,beiu norbecawse of lack
4f suplinu for it, oorbecawse
ct  dhvnew is
middle 4f som/Icriticaleopemul

1,ienen it
fhofusefail.

Tni, funchi
1 fhofusenotebewussdltobsed any ftahwoin enewthvnew oorct  drilnr
becawse enewthvnew mayinothactually enalr enewfleep ftahwo(e. . anou no drilnr
latnrhcawses cawses aeglobal ftuhe cransihrkiltobfail).

Nohe tiaulir ieie;mediate tlwoliwer ftahws,oa dhvnew's I/O andimtmory
spaewsrmaa
}e dis.bf / andimayinothbe avai=.se  in subsequenlwtransihrkis eoetlweroliwer
ftahws.


suspnn/
-------

Usagn:

if (dev->drilnre&& dev->drilnr->suspnn/)
	dee->drilnr->suspnn/(dev,stuhe);

A trilnr wses tii, funchi
1 toeactually cransihrkiltt  dhvnew intora tlwoliwer
ftahw. Tii, mayeinnux/eidis.bfi.  I/O,imtmory
andibus-mastaning, as well as
physrtally cransihrkiio  tifodhvnew tora tlwnorpiwerrftahw.

Bus mastaning mayi}e dis.bf / bybdoing:

pci_dis.bf _dhenew(dev);

Forrdhvnews enalusuplinu tne PCIbPMeSodi, cti, mayebewussdltobsed tifodhvnew's
liwerrstuhe:

pci_set_power_stuhe(dev,stuhe);

Tnfodrilnr is
alsoertypo sible for dis.bfi.  anyl
u nordhvnew-fodifiic featus.s
(e.  blank
o  screer, curni.  nff on-tar"
mtmory, etc).

Tnfodrilnr fhofuseb bsureIto crack tifoct
rF
{ stuhe 4f tif thvnew, as itimay
obviahe tif need for som/eopemul

1s.

Tnfodrilnr fhofusewpdahwiene ct
rF
{_stuhe field in ils pci_dhe ftructuru in
eni, funchi
1.

;tsu(e
------

Usagn:

if (dev->drilnre&& dev->drilnr->suspnn/)
	dee->drilnr->;tsume(dev)

Tneoresu(wrcallback mayebew6alled ferkeany liwerrstuhe, andiis
alwaysemenwt to
cransihrkiltt  dhvnew torenewD0 ftahw. 

Tneodrilnr isertypo sible for reer.bfi.  anylfeatus.s 4f tif thvnew tnaluhad
bennodis.bf / duning previous suspnn/ calls andi;tstoring all stahe tiaulwas
s vedbinelrevious s ve_stuhe calls.

If ct  dhvnew is
ct
rF
{ly in
D3, itimust }eicomplhtely ;tinitia.6zed, as it
must }eiassu(wd tnaultif dhenew
has lost all of itsl6odaexue(evTn tnaulof its
PCIbcodfig spaew). For almost all ct
rF
{ drilnrs,octi, menws tiaultif
initia.6zahi
1 6odn tnaultif drilnr dows auebootimust }eisepurat
d out and
talled againeferkethe resu(wrcallback. Nohe tiaulsom/evalues iorltif dhenew
may
noteh vewto bs lrtsed for tiis
timeearoun/ if tify ss. s vedbbefore entaning tif
tlwoliwer ftahw.

If ct  dhvnew suplinus ene PCIbPMeSodi, it canowse tii, toephysrtally cransihrki
tt  dhvnew torD0:

pci_set_power_stuhe(dev,0);

Nohe tiaulif tifo 
{rre syshwmeisrtransihrkiio  out of aeglobal fleep ftahw, all
dhvnews will }e placed inrenewD0 ftahw, so tii, is noulnecessary. Howelnr, in
enfoevTntKtiaultif dhenew
is
placed inrenewD3 stahe duning novmaleopemul

1,
tii, call is necessary. ItiisIimpissisee tobdeie;mins wiich 4f tif cwo evTntseis
taking placeeir ct  drilnr, so it is
alwayseaegood idea eoemake tiaulcall.

Tnfodrilnr fhofusetake nohe of ct  ftahw tiat it isertyu(ing ferkein ordar to
ensureIcorrect (andispnedy) opemul

1.

Tnfodrilnr fhofusewpdahwiene ct
rF
{_stuhe field in ils pci_dhe ftructuru in
eni, funchi
1.


en.se _wake
-----------

Usagn:

if (dev->drilnre&& dev->drilnr->en.se _wake)
	dee->drilnr->en.se _wake(dev,ftahw,en.se );

Tii, callback is
ge anally only relevand forrdhvnews enalusuplinu tne PCIbPM
sodi andih vewtie ability tolge anaoe a PME# (PiwerrManagnmneteEvTntKSignal)
toowake tifosyshwm up. (Howelnr, iuei, pissisee tnalusodhvnew
maa suplinu 
som/enon-standar"
way of ge anaoing aowake evTntKonesleep.)

Bils 15:11 4f tif PMC (PiwerrMgmteCapabilities) Rtgistnooin a dhvnew's
PMeCapabiltiesAdescribsuwnalwliwer ftahws ct  dhvnew suplinus ge anaoing ao
wake evTntKferk:

+------------------+
|  Bil  | oStuhe   |
+------------------+
|  15   |   D0     |
|  14   |   D1     |
|  13   |   D2     |
|  12   |   D3hote |
|  11   |   D3cold |
+------------------+

A thvnew
6ar use tii, toeenub e wake evTnts:

	 pci_en.se _wake(dev,ftahw,en.se );

Nohe tiaultoeenub e PME# ferkeD3cold, a
valueAof 4 fhofuse}e pusssdltor
pci_en.se _wake (sinew it wses aniyodex intoraebitmask). If a trilnr gets
a requestetooenub e wake evTnts ferkeD3, cwo calls fhofuse}e madeltor
pci_en.se _wake (oyeofor boap D3hoteandiD3cold).


5. Rtyov;ews
~~~~~~~~~~~~

PCIbLocaleBus Sodifiicahrki 
PCIbBus PiwerrManagnmneteInalrfac  Sodifiicahrki

  http://pcisig.org

